//accepted 
#include <cstdio>
int n, x;
int main(){
	//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	scanf("%d", &n);
	while(n){
		
		while(n>9){
			x=n%10;
			while(n/=10){
				x+=n%10;
			}
			n=x;
		}
		printf("%d\n", n);
		
		scanf("%d", &n);
	}
	return 0;
}
